package com.vms.control.weight.model;

import java.util.Arrays;
import java.util.Calendar;
import java.util.Collection;
import java.util.List;


import android.content.Context;

import com.vms.Settings.ValueType;
import com.vms.control.weight.input.IValueChanged;
import com.vms.control.weight.model.DateModel.IOnDateChanged;
import com.vms.healthcontrol.ValueUnderControl;

public class WeightModel {

	private Context mContext;
	private DateModel mDateModel;
	private DataBaseWrapper mDataBase;
	
	public WeightModel(Context mContext, ValueType valueType) {
		this(mContext,Arrays.asList(new ValueType[] {valueType}));
	}
	
	public WeightModel(Context mContext, Collection<ValueType> valueTypes) {
		super();
		this.mContext = mContext;
		this.mDateModel = new DateModel();
		this.mDataBase = new DataBaseWrapper(valueTypes,mContext,mDateModel);
	}
	
	public void saveControlValues() {
		mDataBase.saveControlValues();
	}
	
	/*
	 * Date control 
	 */
	
	public WeightModel setPrevDay() {
		mDateModel.setPrevDay();
		return this;
	}

	public WeightModel setNextDay() {
		mDateModel.setNextDay();
		return this;
	}
	
	public WeightModel setDate(Calendar newCalendar) {
		mDateModel.setDate(newCalendar);
		return this;
	}

	
	public void registerDateChangeListener(IOnDateChanged onDateChanged) {
		mDateModel.registerDateChangeListener(onDateChanged);
	}
	
	public void removeDateChangeListener(IOnDateChanged onDateChanged) {
		mDateModel.removeDateChangeListener(onDateChanged);
	}
	
	public void removeAllDateChangeListener() {
		mDateModel.removeAllDateChangeListener();
	}


	public void updateDate() {
		mDateModel.notifyListeners();
	}

	public CharSequence getCurrentValueFor(ValueType type) {
		return mDataBase.getValue(type);
	}

	public CharSequence getCurrentDimensionFor(ValueType type) {
		return mDataBase.getCurrentDimensionFor(type);
	}

	public void registerOnValueChangeListener(IValueChanged listener) {
		mDataBase.registerOnValueChangeListener(listener);
	}

	public void removeOnValueChangeListener(IValueChanged listener) {
		mDataBase.removeOnValueChangeListener(listener);
	}

	public void increaseValue(ValueType type) {
		mDataBase.increaseValue(type);
	}

	public void decreaseValue(ValueType type) {
		mDataBase.decreaseValue(type);
	}
	
	public void setValue (ValueType type, float value) {
		// TODO Auto-generated method stub
	}
	
	public void selectAll () {
		mDataBase.selectAll();
	}

	public List<ValueUnderControl> getValuesForSelectedDate() {
		return mDataBase.getValuesForSelectedDate();
	}

}
